#include <string.h>

#include "md5.hpp"

namespace crypto
{
	Md5::Md5()
	{
		memset(&_ctx, 0, sizeof(_ctx));
	}

	void Md5::start()
	{
		memset(&_ctx, 0, sizeof(_ctx));
		md5_init_ctx(&_ctx);
	}

	void Md5::process(const void * buffer, size_t len)
	{
		md5_process_bytes(buffer, len, &_ctx);
	}

	void Md5::finish(std::string & resstr)
	{
		uint32_t resbuf[4];

		md5_finish_ctx(&_ctx, (void*)resbuf);

		resstr.assign((char*)resbuf, sizeof(resbuf));
	}
};

